using System;
using System.Collections.Generic;
using System.Net.Mail;
using JetBrains.Annotations;
using Kaleida.ServiceMonitor.Model.Runtime;
using Kaleida.ServiceMonitor.Framework;

namespace Kaleida.ServiceMonitor.Model.ScriptDirectives
{
    public class EmailSummaryDirective : IScriptDirective
    {
    	private readonly IList<MailAddress> recipientEmails;
    	private readonly IList<ScheduledTime> timesOfDay;

		public EmailSummaryDirective([NotNull] string recipients, [NotNull] string time)
        {
			if (recipients == null) throw new ArgumentNullException("recipients");
			if (time == null) throw new ArgumentNullException("time");

			recipientEmails = recipients.ToMailAddressList();
            timesOfDay = time.ToScheduledTimeList();
        }


        public void Apply([NotNull] CompiledScript script)
        {
            if (script == null) throw new ArgumentNullException("script");

            script.EmailSummarySchedule = new EmailSummarySchedule(recipientEmails, timesOfDay);
        }
    }
}